package com.java.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author jl
 * Created on 2020/9/27
 */
public class NIOFileChannel04 {

    public static void main(String[] args) throws Exception{
        // 创建输入流和通道
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\admin\\Desktop\\a.png");
        FileChannel channel = fileInputStream.getChannel();
        // 创建输出流和通道
        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\admin\\Desktop\\b.png");
        FileChannel channel1 = fileOutputStream.getChannel();
        // 通过transferFrom完成拷贝
        channel1.transferFrom(channel,0,channel.size());

        fileInputStream.close();
        fileOutputStream.close();
    }
}
